from django.contrib import admin
from .models import Objective, KeyResult, CheckIn, Team, Comment

@admin.register(Objective)
class ObjectiveAdmin(admin.ModelAdmin):
    list_display = ('title', 'owner', 'start_date', 'end_date', 'status')
    list_filter = ('status', 'owner', 'start_date')
    search_fields = ('title', 'description')
    date_hierarchy = 'created_at'

@admin.register(KeyResult)
class KeyResultAdmin(admin.ModelAdmin):
    list_display = ('title', 'objective', 'assignee', 'progress', 'status')
    list_filter = ('status', 'assignee')
    search_fields = ('title', 'description')
    date_hierarchy = 'created_at'

@admin.register(CheckIn)
class CheckInAdmin(admin.ModelAdmin):
    list_display = ('key_result', 'date', 'previous_progress', 'current_progress', 'created_by')
    list_filter = ('date', 'created_by')
    date_hierarchy = 'date'

@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
    list_display = ('name', 'leader')
    list_filter = ('leader',)
    search_fields = ('name', 'description')
    filter_horizontal = ('members',)

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('created_by', 'get_target', 'created_at')
    list_filter = ('created_by', 'created_at')
    search_fields = ('content',)
    date_hierarchy = 'created_at'
    
    def get_target(self, obj):
        return obj.objective if obj.objective else obj.key_result
    get_target.short_description = '评论对象'
